package com.itheima.controller.backend.Controller;


import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.common.entity.Result;
import com.itheima.controller.backend.Service.SetmealService;
import com.itheima.pojo.Setmeal;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/setmeal")
@Api(tags ="套餐相关接口")
@Slf4j
public class SetmealController {

    @Autowired
    private SetmealService setmealService ;

    @PostMapping("/add")
    @ApiOperation("新增体检套餐")
    public Result addSetmeal(@RequestBody Setmeal setmeal, @RequestParam String checkgroupIds){
        log.info("新增套餐：{},{}",setmeal,checkgroupIds);
        setmealService.addSetmeal(setmeal,checkgroupIds);
        return new Result(true,"新增套餐成功");
    }

    @PostMapping("/edit")
    @ApiOperation("编辑")
    public Result edit(@RequestBody Setmeal setmeal, @RequestParam String checkGroupIds){
        log.info("编辑套餐：{},{}",setmeal,checkGroupIds);
        setmealService.edit(setmeal,checkGroupIds);
        return new Result(true,"编辑套餐成功");
    }

    @GetMapping("/findById")
    @ApiOperation("根据id查询套餐")
    public Result findById(@RequestParam String id){
        log.info("根据id查询套餐：{}",id);
        Setmeal setmeal = setmealService.findById(Integer.parseInt(id));
        return new Result(true,"查询成功",setmeal);
    }

    @PostMapping("/findPage")
    @ApiOperation("分页查询")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        log.info("分页查询:{}",queryPageBean);
        return setmealService.findPage(queryPageBean,queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
    }

    @PostMapping("/upload")
    @ApiOperation("图片上传")
    public Result uploadImage(@RequestParam("imgFile") MultipartFile imgFile){
         return new Result(true,"图片上传成功",setmealService.uploadImage(imgFile));
    }

}
